<template>
  <div class="bs-sysMsg">
    <div class="alert-title" @click="reviewItem()">企业需求</div>
    <div class="msg__content">
        <el-carousel height="40px" direction="horizontal" indicator-position="none" :autoplay="true" :interval="20000">
            <el-carousel-item v-for="(item,index) in requirements" :key="item.requirementId">
                <div class="scroll-item" :style="{ animationDelay: `${index * 5}s` }">
                    <div class="fs14 ml30 color-primary row-center">
                        <div class="fwbold">【{{ item.requirementTypeName }}】</div><div>{{ item.requirement }}</div><div class="ml10">{{item.budget ? `( 预算金额${item.budget}元 )` : '( 服务商报价 )'}}</div>
                    </div>
                 </div>
            </el-carousel-item>
        </el-carousel>
    </div>
    <div class="mr30 fixed-button">
        <button type="button" class="text-button" @click="reviewItem()">查看需求详情 >></button>
    </div>
  </div>
</template>

<script>
import { requirementPage } from '@/api/homeApi'; // Adjust the import path as necessary

export default {
  name: 'AlertSwiper',
  data() {
    return {
      requirements: [],
    };
  },
  mounted() {
    this.fetchRequirements();
  },
  methods: {
    fetchRequirements() {
      requirementPage({ pageNo: 1, pageNum: 100, status:1 }).then((res) => {
        if (res.code === 200) {
          this.requirements = res.rows;
        }
      });
    },
    reviewItem(item) {
      this.$router.push({ name: '企业需求列表' });
    },
  },
};
</script>


<style lang="scss" scoped>
.bs-sysMsg {
    position: relative;
    display: flex;
    background-color: rgba(240, 243, 255, 1); /* Set the background color */
    border: 1px solid rgba(67, 106, 247, 1);
    overflow: hidden;
    opacity: 1;
    align-items: center;
    transition: opacity .2s;
    height: 60px; /* Adjust height as needed */
    margin-top: 10px;
    padding: 10px;
}
.bs-sysMsg .msg__content {
    display: table-cell;
    padding: 0 8px;
    width: 100%;
    height: 40px;
    line-height: 40px;
    text-align: center;
    margin-right: 150px;
}

.scroll-item {
  white-space: nowrap;
  display: inline-block;
  animation: scroll 15s linear infinite;
  animation-delay: 5s; /* Start the animation immediately */
}

@keyframes scroll {
  0% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(-100%);
  }
}

.text-button {
  background: none;
  border: none;
  color: #436AF7;
  cursor: pointer;
  padding: 0;
  font-size: 14px;
}
.fixed-button {
  position: absolute;
  right: 0;
  top: 10px;
  height: 40px;
  line-height: 40px;
  display: flex;
  align-items: center;
  padding-right: 10px;
  cursor: pointer;
  z-index: 99;
}
.alert-title{
  width: 148px;
  height: 40px;
  background-image: url('~@/assets/image/requieBg.png');
  background-size: 100% 100%;
  line-height: 40px;
  position: absolute;
  left: 10px;
  top: 10px;
  color: #fff;
  padding-left: 60px;
  cursor: pointer;
  z-index: 99;
}
</style>


